﻿// ===============================================================================
// XCI.NET 西安交通信息WinForm开发框架 2018 版权所有
// ===============================================================================
namespace XCI.Core
{
    /// <summary>
    /// 分页过滤对象基类
    /// </summary>
    public class BasePageFilter : BaseFilter
    {
        /// <summary>
        /// 构造默认分页对象
        /// </summary>
        public BasePageFilter()
        {
        }

        /// <summary>
        /// 按指定条件构造分页对象
        /// </summary>
        /// <param name="pageIndex">页码索引,从1开始</param>
        /// <param name="pageSize">每页记录数</param>
        public BasePageFilter(int pageIndex, int pageSize)
        {
            PageIndex = pageIndex;
            PageSize = pageSize;
        }

        /// <summary>
        /// 按指定条件构造分页对象
        /// </summary>
        /// <param name="pageIndex">页码索引,从1开始</param>
        /// <param name="pageSize">每页记录数</param>
        /// <param name="orderName">排序字段名称</param>
        /// <param name="dirDir">排序方式(asc/desc)</param>
        public BasePageFilter(int pageIndex, int pageSize, string orderName, string dirDir)
        {
            PageIndex = pageIndex;
            PageSize = pageSize;
            SortName = orderName;
            SortDir = dirDir;
        }

        /// <summary>
        /// 页码索引,从1开始
        /// </summary>
        public int? PageIndex { get; set; }

        /// <summary>
        /// 每页记录数
        /// </summary>
        public int? PageSize { get; set; }

        /// <summary>
        /// 排序字段名称
        /// </summary>
        public string SortName { get; set; }

        /// <summary>
        /// 排序方式(asc/desc)
        /// </summary>
        public string SortDir { get; set; }

        /// <summary>
        /// 清除分页信息
        /// </summary>
        public void ClearPageFilter()
        {
            PageIndex = null;
            PageSize = null;
            SortName = null;
            SortDir = null;
        }

        /// <summary>
        /// 将指定分页过滤对象合并到当前实例
        /// </summary>
        /// <param name="pageFilter">分页过滤对象</param>
        public BasePageFilter CombinePageFilter(BasePageFilter pageFilter)
        {
            if (pageFilter == null) return this;

            this.PageIndex = pageFilter.PageIndex;
            this.PageSize = pageFilter.PageSize;
            this.SortName = pageFilter.SortName;
            this.SortDir = pageFilter.SortDir;
            return this;
        }
    }

    /// <summary>
    /// 分页过滤参数接口
    /// </summary>
    public interface IPageParam
    {
        /// <summary>
        /// 分页过滤参数
        /// </summary>
        BasePageFilter PageFilter { get; set; }
    }
}